require 'korundum4'


class Parser < Qt::Object
    slots 'textDropped(QString*)'
    slots 'datadropped(QString*, QStandardItem*)'
    
    def initialize(droparea)
        super()
        #p "droparea: #{droparea} self: #{self}"
        connect(droparea, SIGNAL('datadropped(QString*, QStandardItem*)'),
                                self, SLOT('datadropped(QString*, QStandardItem*)'))
    end

    def textDropped(text)   # virtual
    end
end

class GmailParser < Parser
    slots 'config()'
    
    def datadropped(text, item)
        #puts "gmailparser...", item.class.to_s
        return unless item.class == Project
        
        name = nil
        text.each { |l|
            #puts "gmail: #{l}"
            name = $2 if l =~ /^tárgy\t(Re: )?(.*)$/
        }
        
        if name
            puts "Gmail name: #{name} project: #{item.name} client: #{item.parent.name}"
            $worker.new_task "Task", item, name
        end
    end
    
    def config()
        p "gmail konfig!!"
        #w = HashEditorWidget.new
        #w.setItemTree @config.hash
        #w.exec
        #@config.hash = w.getItemTree
    end
end

class ETicketParser < Parser
    def datadropped(text, item)
        #puts "e-ticket parser..."
        return unless item.class == Project
        
        name = nil
        text.each { |l|
            #client = l.split[1..10].join ' ' if l =~ /^Category:/
            name = l.split[1..10].join ' ' if l =~ /^Subject:/
        }
        
        if name
            puts "E-ticket name: #{name} project: #{item.name} client: #{item.parent.name}"
            $worker.new_task "Task", item, name
        end
    end
end

$parsers = GmailParser, ETicketParser
